<?php

class DBU_Flash_Messages {

    protected $_flash;

    public function  __construct() {
        $this->_flash = DBU_Flash::instance();
    }

    public function getAll() {
        return (array) $this->_flash->get('messages');
    }

    public function set($message, $type='error') {
        $messages = $this->getEmpty();
        $messages[$type] = $message;
        $this->_flash->add('messages', $messages);
    }

    public function setError($message) {
        return $this->set($message, 'error');
    }

    public function setConfirm($message) {
        return $this->set($message, 'confirm');
    }

    protected function getEmpty() {
         $messages = array(
            'error' => array(),
            'confirm' => array(),
        );
 
        return $messages;
    }

	/**
	 * Returns static instance
	 *
	 * @return DBU_Flash_Messages
	 */
	static public function &instance() {
		static $instance;
		if (!($instance instanceof self)) {
			$instance = new self();
		}
		return $instance;
	}
}